package com.cg.springSecurity.valid;

import com.cg.springSecurity.annotation.TinyInt;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;

/**
 * @author cg
 * @date 2023/3/30 9:28
 */
public class TinyIntValidator implements ConstraintValidator<TinyInt,Integer> {

    private Set<Integer> set = new HashSet<>();
    @Override
    public void initialize(TinyInt constraintAnnotation) {
        for (int val : constraintAnnotation.vals()) {
            set.add(val);
        }
    }

    @Override
    public boolean isValid(Integer integer, ConstraintValidatorContext constraintValidatorContext) {
        return set.contains(integer);
    }
}
